$(function () {
    getSkuProduct(params()["id"]);
})
function toSkuProductEdit(id) {
    /*localStorage.setItem("id",id);*/
    window.location.href = "skuProductEdit.do?ran=" + Math.random() + "&skuId=" + id;
}

function getSkuProduct(id) {
    $.ajax({
        url: server_url + '/rest/product/getSkuProductInfo.do?ran=' + Math.random(),
        type: 'post',
        async: false,
        data: {id: id,ran:Math.random()},
        success: function (data) {
            console.log(data.data);
            if (data.retCode == "0000") {
                $("#pro").click(function () {
                    toSkuProductEdit(data.data.id);
                });
                var s = '';
                var s = '<div class="con_tit" onclick="toSkuProductEdit(' + data.data.id + ')">\
                            <p>' + data.data.productName + '</p>\
                            <span>¥' + data.data.price + '/头</span>\
                            </div>\
                            <p class="con_normal">类别：' + data.data.specName + ' <span>'+approveStatusName(data.data.approveStatus)+'</span></p>\
                        <p class="con_normal">库存：' + data.data.overPlusNum + '头</p>\
                        <p class="con_normal">备注：' + data.data.remark + '</p>\
                        <p class="con_normal">'+data.data.modifyTime.substr(0,10)+'</p>\
                        <p class="con_normal">编号：' + data.data.id + '</p>';
                $("#detail").append(s);
                $("#img").attr("src",data.data.picturePath1);
            }
            else {
                easyDialog.open({
                    container: {
                        header: '提示',
                        content: data.retMsg
                    },
                    autoClose: 2000
                });
            }
        }
    });
}
function approveStatusName(app){
    if(app == '1'){
        return "审核中";
    }
    if(app == '2'){
        return '审核不通过'
    }
    if(app == '3'){
        return "审核通过"
    }
}
//下架
function sureStatusSwitchs(id) {
    //if(confirm("您确定要下架吗？"))
    //console.log(id);
    //console.log(confirmUtil("您确定要下架吗？"));
    confirmUtil("您确定要下架吗？", function (r) {
        if (r) {
            $.ajax({
                url: server_url + '/rest/product/changeStatusSwitchs.do',
                type: 'post',
                dataType: 'json',
                data: {
                    id: id,ran:Math.random()
                },
                success: function (data) {
                    if (data.retCode = "0000") {
                        easyAlert("下架成功！");
                        back();
                    } else {
                        easyAlert("下架失败！");
                    }
                }
            });
        }
    })
}
//上架
function sureStatusSwitch(ids) {
    confirmUtil("您确定要上架吗？", function (r) {
        if (r) {
            $.ajax({
                url: server_url + '/rest/product/changeStatusSwitch.do',
                type: 'post',
                dataType: 'json',
                data: {
                    ids: ids,ran:Math.random()
                },
                success: function (data) {
                    if (data.retCode = "0000") {
                        easyAlert("上架成功！");
                        back();
                    } else {
                        easyAlert("上架失败！");
                    }
                }
            });
        }
    });
}
function back() {
    window.location.href = "index.do?ran=" + Math.random();
}
